package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping("/search")
    @ApiOperation(value = "条件分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage(@RequestParam(required = false) String name,
                                                                 @RequestParam(required = false) Integer status,
                                                                 @RequestParam(required = true,defaultValue = "1") Integer pageNum,
                                                                 @RequestParam(required = true,defaultValue = "10") Integer pageSize){
        PageResponse<NursingPlanVo> byPage=nursingPlanService.getByPage(name,status,pageNum,pageSize);
        return  ResponseResult.success(byPage);
    }

    @GetMapping
    @ApiOperation(value = "查询所有护理计划")
    public ResponseResult<NursingPlanVo> selectAllNursingPlan(){
        List<NursingPlanVo> nursingPlanVo=nursingPlanService.selectAllNursingPlan();
        return ResponseResult.success(nursingPlanVo);
    }

    @PostMapping
    @ApiOperation(value = "新增护理计划")
    public ResponseResult insertNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.insertNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Long id){
        NursingPlanVo nursingPlanVo=nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "修改")
    public ResponseResult updateNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.updateNursingPlan(nursingPlanDto);

        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public ResponseResult deleteNursingPlan(@PathVariable List<Integer> id){
        nursingPlanService.deleteNursingPlan(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult updateStatus(@PathVariable Integer id,@PathVariable Integer status){
        nursingPlanService.updateStatus(id,status);
        return ResponseResult.success();
    }
}
